# -*- coding: utf-8 -*-
# @Time    : 2023/9/19 15:07
# @Author  : chenyinhua
# @File    : common_page.py
# @Software: PyCharm
# @Desc:

# 标准库导入
# 第三方库导入
# 本地应用/模块导入
from case_utils.base_page import BasePage


class CommonPage(BasePage):
    def open_site(self, url):
        """
        访问指定的页面
        """
        self.visit(url)

    def check_current_url(self, url):
        """
        检查页面路由，接受一个字符串参数或正则表达式参数
        """
        self.have_url(url)

    def check_page_title(self, text):
        """
        检查网页标题，接受一个字符串参数或正则表达式参数
        """
        self.have_title(text)

    def click_new_icon(self):
        """
        点击导航栏右上角的新建图标
        """
        self.click(locator="xpath=//i[contains(@class, 'icon-sousuo')]/following-sibling::img")

    def click_new_project_button(self):
        """
        点击新建图标下的新建项目按钮，进入新建项目页面
        """
        self.click(locator="xpath=//a[text()='新建项目']")

    def click_login_button_on_nav(self):
        """
        点击导航栏右上角的登录按钮，进入登录页面
        """
        self.click(locator="xpath=//a[text()='登录']")

    def click_confirm_button(self):
        """
        点击"确定”按钮
        """
        self.click("xpath=//a[text()='确定']")

    def upload_attachments(self, files: list):
        """
        上传疑修附件
        """
        for file_path in files:
            self.upload_file(locator="//p[text()='拖动文件或点击此处上传']/parent::div/preceding-sibling::input",
                             file_path=file_path)

    def check_login(self, login):
        """
        登录成功后，获取用户的login
        """
        self.is_element_attr_have_value(locator="xpath=//a[@class='ant-dropdown-trigger']", attr_name="href",
                                        value=login)
